home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / gtkinklevel.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  4KB  |  115 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import gtk
  5. import cairo
  6.  
  7. class GtkInkLevel(gtk.DrawingArea):
  8.     
  9.     def __init__(self, color, level = 0):
  10.         gtk.DrawingArea.__init__(self)
  11.         self.connect('expose-event', self.expose_event)
  12.         self._level = level
  13.         
  14.         try:
  15.             self._color = gtk.gdk.color_parse(color)
  16.         except (ValueError, TypeError):
  17.             self._color = gtk.gdk.color_parse('#cccccc')
  18.  
  19.         self.set_size_request(30, 45)
  20.  
  21.     
  22.     def set_level(self, level):
  23.         self._level = level
  24.         self.queue_resize()
  25.  
  26.     
  27.     def get_level(self):
  28.         return self._level
  29.  
  30.     
  31.     def expose_event(self, widget, event):
  32.         ctx = self.window.cairo_create()
  33.         ctx.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
  34.         ctx.clip()
  35.         (w, h) = self.window.get_size()
  36.         ratio = 1 * h / w
  37.         if ratio < 1.5:
  38.             w = h * 2 / 3
  39.         else:
  40.             h = w * 3 / 2
  41.         thickness = 1
  42.         ctx.translate(thickness, thickness)
  43.         ctx.scale(w - 2 * thickness, h - 2 * thickness)
  44.         thickness = max(ctx.device_to_user_distance(thickness, thickness))
  45.         ctx.set_line_width(thickness)
  46.         self.draw(ctx)
  47.  
  48.     
  49.     def draw(self, ctx):
  50.         r = self._color.red / 65535
  51.         g = self._color.green / 65535
  52.         b = self._color.blue / 65535
  53.         fill_point = self._level / 100
  54.         ctx.move_to(0.5, 0)
  55.         ctx.curve_to(0.5, 0.33, 1, 0.5, 1, 0.67)
  56.         ctx.curve_to(1, 0.85, 0.85, 1, 0.5, 1)
  57.         ctx.curve_to(0.15, 1, 0, 0.85, 0, 0.67)
  58.         ctx.curve_to(0, 0.5, 0.1, 0.2, 0.5, 0)
  59.         ctx.close_path()
  60.         ctx.set_source_rgb(r, g, b)
  61.         ctx.stroke_preserve()
  62.         if fill_point > 0:
  63.             grad_width = 0.1
  64.             grad_start = fill_point - grad_width / 2
  65.             if grad_start < 0:
  66.                 grad_start = 0
  67.             
  68.             pat = cairo.LinearGradient(0, 1, 0, 0)
  69.             pat.add_color_stop_rgba(0, r, g, b, 1)
  70.             pat.add_color_stop_rgba((self._level - 5) / 100, r, g, b, 1)
  71.             pat.add_color_stop_rgba((self._level + 5) / 100, 1, 1, 1, 1)
  72.             pat.add_color_stop_rgba(1, 1, 1, 1, 1)
  73.             ctx.set_source(pat)
  74.             ctx.fill()
  75.         else:
  76.             ctx.set_source_rgb(1, 1, 1)
  77.             ctx.fill()
  78.  
  79.  
  80. if __name__ == '__main__':
  81.     import gobject
  82.     import time
  83.     
  84.     def adjust_level(level):
  85.         l = level.get_level()
  86.         l += 1
  87.         if l > 100:
  88.             l = 0
  89.         
  90.         level.set_level(l)
  91.         return True
  92.  
  93.     w = gtk.Window()
  94.     w.set_border_width(12)
  95.     vbox = gtk.VBox(spacing = 6)
  96.     w.add(vbox)
  97.     hbox = gtk.HBox(spacing = 6)
  98.     vbox.pack_start(hbox, False, False, 0)
  99.     klevel = GtkInkLevel('black', level = 100)
  100.     clevel = GtkInkLevel('cyan', level = 60)
  101.     mlevel = GtkInkLevel('magenta', level = 30)
  102.     ylevel = GtkInkLevel('yellow', level = 100)
  103.     hbox.pack_start(klevel)
  104.     hbox.pack_start(clevel)
  105.     hbox.pack_start(mlevel)
  106.     hbox.pack_start(ylevel)
  107.     gobject.timeout_add(10, adjust_level, klevel)
  108.     gobject.timeout_add(10, adjust_level, clevel)
  109.     gobject.timeout_add(10, adjust_level, mlevel)
  110.     gobject.timeout_add(10, adjust_level, ylevel)
  111.     w.show_all()
  112.     w.connect('delete_event', gtk.main_quit)
  113.     gtk.main()
  114.  
  115.